package com.cnzhy.pool;

import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.Connection;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Logger;

/**
 * @author 赵 岩
 */
public class MyDataSource implements DataSource {

    /**
     * 链表 --- 实现栈结构
     */
    private static final ConcurrentLinkedQueue<Connection> dataSources = new ConcurrentLinkedQueue<>();


    @Override
    public Connection getConnection() {
        // 取出连接池中一个连接 , 删除第一个连接返回
        return dataSources.poll();
    }

    public static Connection getConnectionFromPool() {
        // 取出连接池中一个连接 , 删除第一个连接返回
        return dataSources.poll();
    }

    /**
     * 将连接放回连接池
     */
    public static void releaseConnection(Connection conn) {
        dataSources.add(conn);
    }

    @Override
    public PrintWriter getLogWriter() {
        return null;
    }

    @Override
    public void setLogWriter(PrintWriter out) {

    }

    @Override
    public void setLoginTimeout(int seconds) {

    }

    @Override
    public int getLoginTimeout() {
        return 0;
    }


    @Override
    public Logger getParentLogger() {
        return null;
    }

    @Override
    public <T> T unwrap(Class<T> iface) {
        return null;
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) {
        return false;
    }

    @Override
    public Connection getConnection(String username, String password) {
        return null;
    }
}
